package com.wh.wisdomsite.xbox.ba.entity;

import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType;
import com.wh.wisdomsite.xbox.utils.StringUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.Map;
import java.util.UUID;

/**
 * 系统日志实体
 * @Package: com.wh.wisdomsite.xbox.us.entity
 * @author: 丁奕
 * @date: 2018-08-08 17:25
 * @Copyright 公司版权所有
 * @Company 贵州万华科技有限公司Copyright (c) 2016
 * @version V1.0
 **/
@TableName("ba_sysLog")
public class SysLog extends Model<SysLog> {

    /**
     * PK, 公共系统配置ID
     */
    @TableId(type = IdType.UUID)
    private String slId;

    /**
     *日志类型：
     * 1：菜单操作
     * 2：按钮操作
     */
    @TableField("type")
    private String type;

    // 日志类型（1：菜单操作；2：按钮操作）
    @TableField( exist = false)
    public static final String TYPE_PAGE = "1";
    @TableField( exist = false)
    public static final String TYPE_BUTTON = "2";

    /**
     *日志代码，系统定义唯一 
     */
    @TableField("slCode")
    private String slCode;

    /**
     *日志标题 
     */
    @TableField("title")
    private String title;

    /**
     *操作IP地址 
     */
    @TableField("remoteAddr")
    private String remoteAddr;

    /**
     *请求地址 
     */
    @TableField("reqUrl")
    private String reqUrl;

    /**
     *用户代理
     */
    @TableField("userAgent")
    private String userAgent;

    /**
     *请求类型
     */
    @TableField("method")
    private String method;

    /**
     *请求参数
     */
    @TableField("params")
    private String params;

    /**
     *异常信息
     */
    @TableField("exception")
    private String exception;

    /**
     * 创建者
     */
    @TableField("createBy")
    private String createBy;

    /**
     * 创建时间
     */
    @TableField("createDate")
    private Date createDate;

    public String getSlId() {
        return slId;
    }

    public void setSlId(String slId) {
        this.slId = slId;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getSlCode() {
        return slCode;
    }

    public void setSlCode(String slCode) {
        this.slCode = slCode;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getRemoteAddr() {
        return remoteAddr;
    }

    public void setRemoteAddr(String remoteAddr) {
        this.remoteAddr = remoteAddr;
    }

    public String getReqUrl() {
        return reqUrl;
    }

    public void setReqUrl(String reqUrl) {
        this.reqUrl = reqUrl;
    }

    public String getUserAgent() {
        return userAgent;
    }

    public void setUserAgent(String userAgent) {
        this.userAgent = userAgent;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getParams() {
        return params;
    }

    public void setParams(Map paramMap){
        if (paramMap == null){
            return;
        }
        StringBuilder params = new StringBuilder();
        for (Map.Entry<String, String[]> param : ((Map<String, String[]>)paramMap).entrySet()){
            params.append(("".equals(params.toString()) ? "" : "&") + param.getKey() + "=");
            String paramValue = (param.getValue() != null && param.getValue().length > 0 ? param.getValue()[0] : "");
            params.append(StringUtils.abbr(org.apache.commons.lang3.StringUtils.endsWithIgnoreCase(param.getKey(), "password") ? "" : paramValue, 100));
        }
        this.params = params.toString();
    }

    public String getException() {
        return exception;
    }

    public void setException(String exception) {
        this.exception = exception;
    }

    public String getCreateBy() {
        return createBy;
    }

    public void setCreateBy(String createBy) {
        this.createBy = createBy;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    @Override
    protected Serializable pkVal() {
        return this.slId;
    }
}
